<script setup lang="ts">
import {useRouter} from "vue-router";
import {onMounted, ref} from "vue";
import {getCurrentUser} from "../service/user.ts";
import {userGenderEnum} from "../constants/user.ts";
import myAxios from "../plugins/myAxios.ts";
import {showFailToast, showSuccessToast} from "vant";



const router = useRouter();
const toEdit = (editKey: string, editName: string, currentValue: string) => {
  router.push({
    path: '/user/edit',
    query: {
      editKey,
      currentValue,
      editName
    }
  })
}

const user = ref();

const doLogout = async () => {
  const res = await myAxios.post('/user/logout')
  if (res?.code === 200) {
    showSuccessToast('退出成功')
    await router.replace('/user/login')
  } else {
    showFailToast('退出失败')
  }
}

onMounted(async () => {
  user.value = await getCurrentUser();
})
</script>

<template>
  <div v-if="user">
    <van-cell title="当前用户" :value="user?.username" />
    <van-cell title="修改信息" is-link to="/user/update" />
    <van-cell title="我创建的队伍" is-link to="/user/team/create" />
    <van-cell title="我加入的队伍" is-link to="/user/team/join" />
    <van-cell title="退出登录" @click="doLogout" />
  </div>
</template>

<style scoped>

</style>
